define(function (require, exports, module) {

    require("apps/easyui");
    function isHtml5() {
//        return false;
        return !!document.createElement('canvas').getContext && !isIE();
    }
    function isIE(){
//        return false;
        return navigator.appName == 'Microsoft Internet Explorer';
    }
    require("uploadify/html5/jquery.Huploadify");
    require("uploadify/jquery.uploadify.min");
    if (isHtml5()) {
        require.async("uploadify/html5/Huploadify.css");
    } else {
        require.async("uploadify/uploadify.css");
    }


    (function ($) {

        var fileStr = {
            zip: "fa fa-file-zip-o fa-3x",
            bmp: "fa fa-file-photo-o fa-3x",
            doc: "fa fa-file-word-o fa-3x",
            docx: "fa fa-file-word-o fa-3x",
            jpg: "fa fa-file-photo-o fa-3x",
            jpeg: "fa fa-file-photo-o fa-3x",
            mp3: "fa fa-file-audio-o fa-3x",
            pdf: "fa fa-file-pdf-o fa-3x",
            png: "fa fa-file-photo-o fa-3x",
            ppt: "fa fa-file-powerpoint-o fa-3x",
            pptx: "fa fa-file-powerpoint-o fa-3x",
            rar: "fa fa-file-zip-o fa-3x",
            txt: "fa fa-file-text-o fa-3x",
            text: "fa fa-file-text-o fa-3x",
            wma: "fa fa-file-video-o fa-3x",
            wmv: "fa fa-file-video-o fa-3x",
            xls: "fa fa-file-excel-o fa-3x",
            xlsx: "fa fa-file-excel-o fa-3x"
        };


        $.widget("custom.fileupload", {
            options: {
                width: 80,
                height: 30,
                postData: {},
                selectText: "文件上传",
                containsForm: true,
                display: "inline-block",
                maxUploadNumber: 1,

                onUploadSuccess: $.noop,
                onUploadFailure: function () {
                    this.dg.dialog("close");
                },
                onDialogClose: $.noop
            },
            _createDialog: function () {
                this.queueID = $.utils.createUUID(6);
                var that = this;
                this.dg = $("<div><div id='" + this.queueID + "' class='simple-upload'></div></div>").appendTo("body");
                this.queueBox = this.dg.children();
                this.queueBox.addClass("uploadify-image-queue");
                this.dg.dialog({
                    width: 400,
                    closed: true,
                    title: "文件上传列表",
                    closable: false,
                    modal: true,
                    buttons: [
                        {
                            text: "取消上传",
                            handler: function (event) {
                                that.cancelAll();
                                that.dg.dialog("close");
                            }
                        }
                    ]
                });
            },
            addFile:function(fileName, filePath){
                var v = $.trim(filePath);
                v = v.length > 0 ? v.split(",") : [];
                var vName = $.trim(fileName);
                vName = vName.length > 0 ? vName.split(",") : [];
                if (v.length) {
                    var hasNames = vName.length > 0;
                    for (var i = 0, l = v.length; i < l; i++) {
                        var uuid = $.utils.createUUID(10);
                        var pos = v[i].lastIndexOf("/");
                        var _name = hasNames ? vName[i] : v[i].substr(pos + 1);
                        this._renderQuery.call(this, {
                            id: uuid,
                            fileName: _name,
                            filePath: v[i]
                        }, false);
                    }
                    var files = [];
                    this.queueBox.children().each(function () {
                        var obj = $(this).clone(false).appendTo("body");
                        var html = obj.find(".uploadify-progress")
                            .remove().end().html();
                        obj.remove();
                        var data = $.extend({}, $(this).data(), {fileHtml: html});
                        files.push(data);
                    });
                    files.reverse();
                    this.options.onUploadSuccess.call(this, files, true);
                }
            },
            _renderQuery: function (data, hasProgress) {
                var $this = this;
                var itemHtml = '<div id="{{id}}" class="uploadify-queue-item" data-name="{{fileName}}" data-href="{{filePath}}"><div>\
						<div class="uploadify-file" style="border-bottom: 1px solid #ccc; margin: 0px auto; width: 95%; padding: 5px 0px;">\
						    <i class="{{_fileType}}"></i>\
						    <span style="font-size: 16px;">{{fileName}}</span>\
			           </div>';
                if (hasProgress) {
                    itemHtml += '<div class="uploadify-progress">\
                            <div class="uploadify-progress-bar"><!--Progress Bar--></div>\
                            </div><span class="data"></span>';
                }
                itemHtml += '</div></div>';
                var fileName = data.fileName, item = {};

                item._fileType = "fa fa-file fa-3x";
                if (fileName) {
                    var l = fileName.lastIndexOf(".");
                    if (l > 0) {
                        var t = fileName.substr(l + 1).toLowerCase();
                        if (fileStr[t]) {
                            item._fileType = fileStr[t];
                        }
                    }
                }
                var detail = $(Mustache.render(itemHtml, $.extend(item, data))).prependTo($this.queueBox);
                var maxNum = $this.queueBox.children().each(function (i, item) {
                    if ((i + 1) > $this.options.maxUploadNumber) {
                        $(item).remove();
                    }
                });
            },
            _create: function () {
                var that = this;
                this.uploadFrame = $("<a href='javascript:void(0)'></a>").insertAfter(this.element).attr("id", $.utils.createUUID(8));
                this.element.hide();
                if (!this.options.width) {
                    this.options.width = this.uploadFrame.outerWidth();
                }
                this.wrapper = $("<div>").addClass("simple-upload-wrapper").addClass(this.options.cls)
                    .css({display: this.options.display}).insertAfter(this.uploadFrame).css("width", this.options.width);
                this.uploadFrame.appendTo(this.wrapper);
                this._createDialog();
                var v = this.element.val() || "", vName = this.element.attr("data-name") || "";
                this.addFile(vName, v);
                var formData = $.extend({}, this.options.postData, {iPlanetDirectoryPro: $.utils.loadCookie('iPlanetDirectoryPro')});
                var _options = $.extend({}, this.options);
                this.cache = [];
                this._userOptions = $.extend(_options, {
                    userSettings: that,
                    buttonClass: "upload-button",
                    buttonText: this.options.selectText,
                    width: this.options.width,
                    height: this.options.height,
                    swf: WE.contextPath + '/static/js/uploadify/uploadify.swf',
                    queueID: this.queueID,
                    auto: true,
                    formData: formData,
                    overrideEvents: ["onSelect", "onUploadComplete", "onUploadError"],
                    onUploadSuccess: function (file, data, response) {
                        console.log(arguments);
                        var $this = this.settings.userSettings;
                        var json = eval('(' + data + ')');
                        var fi = $('#' + file.id).addClass("uploadify-queue-success")
                            .attr("data-href", json.attachment)
                            .attr("data-name", json.attachmentName);
                        if (json.width) {
                            fi.attr("data-width", json.width);
                            fi.attr("data-height", json.height);
                        }
                        var d = [], sn = [];
                        $this.queueBox.children().each(function () {
                            var v = $(this).attr("data-href"), n = $(this).attr("data-name");
                            d.push(v);
                            sn.push(n);
                        });
                        var _v = d.join(",");
                        $this.element.val(_v).attr("data-name", sn.join(","));
                    },
                    onQueueComplete: function () {
                        var $this = this.settings.userSettings;
                        if ($this.uploadError) {

                        } else {
                            $this.uploading = false;
                            $this.dg.dialog("close");
                            var files = [];
                            $this.queueBox.children().each(function () {
                                var obj = $(this).clone(false).appendTo("body");
                                var html = obj.find(".uploadify-progress")
                                    .remove().end().html();
                                obj.remove();
                                var data = $.extend({}, $(this).data(), {fileHtml: html});
                                files.push(data);
                            });
                            files.reverse();
                            $this.options.onUploadSuccess.call($this, files, false);
                        }
                    },
                    onDialogOpen: function () {
                        var $this = this.settings.userSettings;
                        $this.uploading = true;
                    },
                    onUploadProgress: function (file, fileBytesLoaded, fileTotalBytes, queueBytesLoaded, uploadSize) {
                        $('#' + file.id).find('.data').addClass("simple-upload-progress");
                    },
                    onDialogClose: function (queueData) {
                        var $this = this.settings.userSettings;
                        $this.uploading = queueData.filesSelected;
                        $this.uploadError = false;
                        if ($this.uploading) {
                            $this.dg.dialog("open");
                        }
                    },
                    onUploadError: function (file, errorCode, errorMsg, errorString) {
                        var $this = this.settings.userSettings;
                        if (errorCode != SWFUpload.UPLOAD_ERROR.FILE_CANCELLED && errorCode != SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED) {
                            $('#' + file.id).addClass('uploadify-error');
                        }
                        // Reset the progress bar
                        $('#' + file.id).find('.uploadify-progress-bar').css('width', '1px');

                        // Add the error message to the queue item
                        if (errorCode != SWFUpload.UPLOAD_ERROR.SPECIFIED_FILE_ID_NOT_FOUND && file.status != SWFUpload.FILE_STATUS.COMPLETE) {
                            $('#' + file.id).find('.data').html(errorString);
                        }
                        $this.uploadError = true;
                    },
                    onUploadComplete: function (file) {
                        var swfuploadify = this;
                        switch (file.filestatus) {
                            case SWFUpload.FILE_STATUS.COMPLETE:
                                setTimeout(function () {
                                    if ($('#' + file.id).length) {
                                        if (swfuploadify.queueData) {
                                            swfuploadify.queueData.queueSize -= file.size;
                                            swfuploadify.queueData.queueLength -= 1;
                                            delete swfuploadify.queueData.files[file.id];
                                        }
                                        $('#' + file.id).find(".uploadify-progress").fadeOut(500, function () {
                                            $(this).remove();
                                        });
                                    }
                                }, 200);
                                break;
                            case SWFUpload.FILE_STATUS.ERROR:
                                setTimeout(function () {
                                    if ($('#' + file.id).length) {
                                        if (swfuploadify.queueData) {
                                            swfuploadify.queueData.queueSize -= file.size;
                                            swfuploadify.queueData.queueLength -= 1;
                                            delete swfuploadify.queueData.files[file.id];
                                        }
                                        $('#' + file.id).find(".uploadify-progress").fadeOut(500, function () {
                                            $(this).remove();
                                        });
                                    }
                                }, 200);
                                break;
                        }
                    },
                    onSelect: function (file) {
                        var $this = this.settings.userSettings;
                        var _file = {
                            id: file.id,
                            fileName: file.name
                        };
                        $this._renderQuery.call($this, _file, true);
                    }

                });
                if (isHtml5) {
                    this.uploadComponent = this.uploadFrame.Huploadify(this._userOptions);
                } else {
                    this.uploadFrame.uploadify('init', this._userOptions);
                }
            },
            _setOptions: function (options) {
                var that = this;
                $.each(options, function (key, value) {
                    that._setOption(key, value);
                });
                $("#" + that.queueID).empty();
                if (isHtml5) {
                    this.uploadComponent.destroy();
                    this.uploadComponent = this.uploadFrame.Huploadify(this._userOptions);
                } else {
                    this.uploadFrame.uploadify('destroy');
                    this.uploadFrame.uploadify('init', this._userOptions);
                }
            },
            _destroy: function () {
                if (isHtml5) {
                    this.uploadComponent.destroy();
                } else {
                    this.uploadFrame.uploadify('destroy');
                }
                this.wrapper.remove();
                this.element.show();
            },
            cancelAll: function () {
                if (isHtml5) {
                    this.uploadComponent.cancel("*");
                } else {
                    this.uploadFrame.uploadify('cancel', '*');
                }
            }
        });
    })(jQuery);
    (function ($) {
        $.widget("custom.baseImageUpload", {
            options: {
                width: 80,
                height: 30,
                postData: {},
                userUploadifySettings: {},
                uploadCompleteShowButton: true,
                queueBox: null,
                cls: "",
                selectText: "选择图片",
                cancelButton: true,
                multi: false,
                onUploadBefore: true,
                onUploadSuccess: $.noop,
                onUploadProgress: $.noop,
                imageSize: [100, 75],
                maxUploadNumber: 1,
                onCancel: $.noop
            },
            _getImagesSize: function () {
                return this.options.imageSize[0] + "x" + this.options.imageSize[1];
            },
            addFile:function(fileName, filePath){
                var v = filePath.split(",");
                var vName = fileName.split(",");
                if (v.length) {
                    var hasNames = vName.length > 0;
                    for (var i = 0, l = v.length; i < l; i++) {
                        var uuid = $.utils.createUUID(10);
                        var pos = v[i].lastIndexOf("/");
                        var _name = hasNames ? vName[i] : v[i].substr(pos + 1);
                        this._renderQuery.call(this, {
                            id: uuid,
                            fileName: _name,
                            filePath: v[i]
                        }, false);
                    }
                    var files = [];
                    this.queueBox.children().each(function () {
                        var obj = $(this).clone(false).appendTo("body");
                        var html = obj.find(".uploadify-progress")
                            .remove().end().html();
                        obj.remove();
                        var data = $.extend({}, $(this).data(), {fileHtml: html});
                        files.push(data);
                    });
                    files.reverse();
                    this.options.onUploadSuccess.call(this, files, true);
                }
            },
            _writeImageOptions: function () {
                return $.extend({
                    onUploadSuccess: function (file, data, response) {
                        var $this = this.settings.userSettings;
                        var json = eval('(' + data + ')');
                        $('#' + file.id).addClass("uploadify-queue-success")
                            .attr("data-href", json.attachment)
                            .attr("data-name", json.attachmentName);
                        var d = [];
                        $this.queueBox.children().each(function () {
                            var v = $(this).attr("data-href");
                            d.push(v);
                            $(this).find("img").attr("src", WE.contextPath + "/print/" + v);
                        });
                        var _v = d.join(",");
                        $this.element.val(_v);
                    },
                    onUploadError: function (file, errorCode, errorMsg, errorString) {
                        if (errorCode != SWFUpload.UPLOAD_ERROR.FILE_CANCELLED && errorCode != SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED) {
                            $('#' + file.id).addClass('uploadify-error');
                        }
                        // Reset the progress bar
                        $('#' + file.id).find('.uploadify-progress-bar').css('width', '1px');

                        // Add the error message to the queue item
                        if (errorCode != SWFUpload.UPLOAD_ERROR.SPECIFIED_FILE_ID_NOT_FOUND && file.status != SWFUpload.FILE_STATUS.COMPLETE) {
                            $('#' + file.id).find('.uploadify-img').html(errorString);
                        }
                    },
                    onUploadComplete: function (file) {
                        var swfuploadify = this;
                        switch (file.filestatus) {
                            case SWFUpload.FILE_STATUS.COMPLETE:
                                setTimeout(function () {
                                    if ($('#' + file.id)) {
                                        if (swfuploadify.queueData) {
                                            swfuploadify.queueData.queueSize -= file.size;
                                            swfuploadify.queueData.queueLength -= 1;
                                            delete swfuploadify.queueData.files[file.id];
                                        }
                                        $('#' + file.id).find(".uploadify-progress").fadeOut(500, function () {
                                            $(this).remove();
                                        });
                                    }
                                }, 200);
                                break;
                            case SWFUpload.FILE_STATUS.ERROR:
                                setTimeout(function () {
                                    if ($('#' + file.id)) {
                                        if (swfuploadify.queueData) {
                                            swfuploadify.queueData.queueSize -= file.size;
                                            swfuploadify.queueData.queueLength -= 1;
                                            delete swfuploadify.queueData.files[file.id];
                                        }
                                        $('#' + file.id).find(".uploadify-progress").fadeOut(500, function () {
                                            $(this).remove();
                                        });
                                    }
                                }, 200);
                                break;
                        }
                    },
                    onQueueComplete: function () {
                        var $this = this.settings.userSettings;

                    },
                    onUploadStart: function () {

                    },
                    onSelect: function (file) {
                        var $this = this.settings.userSettings;
                        $this._renderQuery.call($this, file, true);
                    }
                }, this.options.userUploadifySettings);
            },
            _renderQuery: function (data, hasProgress) {
                var $this = this;
                var _data = $.extend({}, data, {
                    width: $this.options.imageSize[0],
                    height: $this.options.imageSize[1],
                    _filePath: WE.contextPath + "/print" + data.filePath
                });
                var itemHtml = '<div id="{{id}}" class="uploadify-queue-item" data-name="{{fileName}}" data-href="{{filePath}}">\
						<div class="uploadify-img" style="border: 1px solid #CCC">\
					    <img alt="{{fileName}}" width="{{width}}" src="{{_filePath}}" height="{{height}}" /></div>';
                if (hasProgress) {
                    itemHtml += '<div class="uploadify-progress">\
                            <div class="uploadify-progress-bar"><!--Progress Bar--></div>\
                            </div><span class="data"></span>';
                }
                itemHtml += '</div>';
                var detail = $(Mustache.render(itemHtml, _data)).prependTo($this.queueBox);
                var maxNum = $this.queueBox.children().each(function (i, item) {
                    if (i + 1 > $this.options.maxUploadNumber) {
                        $(item).remove();
                    }
                });
                detail.find(".uploadify-img").css({width: _data.width, height: _data.height});
                detail.find("div.uploadify-progress").width(_data.width);
            },
            _create: function () {
                var that = this;
                this.uploadFrame = $("<a href='javascript:void(0)'></a>").insertAfter(this.element).attr("id", $.utils.createUUID(8));
                this.element.hide();
                if (!this.options.width) {
                    this.options.width = this.uploadFrame.outerWidth();
                }
                this.wrapper = $("<div>").addClass("simple-upload-wrapper").addClass(this.options.cls).insertAfter(this.uploadFrame);
                this.uploadFrame.appendTo(this.wrapper);
                this.queueBox = this.options.queueBox ? $(this.options.queueBox) : $('<div></div>').insertBefore(this.uploadFrame);
                this.queueID = this.queueBox.attr("id");
                if (!this.queueID) {
                    this.queueID = $.utils.createUUID(10);
                    this.queueBox.attr("id", this.queueID);
                }
                this.queueBox.addClass("uploadify-image-queue");
                var v = this.element.val() || "", vName = this.element.attr("data-name") || "";
                this.addFile(vName, v);
                var formData = $.extend({}, this.options.postData, {iPlanetDirectoryPro: $.utils.loadCookie('iPlanetDirectoryPro')});
                var _options = $.extend({}, this.options);
                this._userOptions = $.extend(_options, {
                    userSettings: that,
                    buttonClass: "upload-button",
                    buttonText: this.options.selectText,
                    width: this.options.width,
                    height: 32,
                    auto: true,
                    fileTypeDesc: '*.jpg;*.jpeg;*.gif;*.png;',
                    fileTypeExts: '*.jpg;*.jpeg;*.gif;*.png;',
                    swf: WE.contextPath + '/static/js/uploadify/uploadify.swf',
                    queueID: this.queueID,
                    formData: formData,
                    overrideEvents: ["onSelect", "onUploadComplete", "onUploadError"]
                }, this._writeImageOptions());
                if (isHtml5) {
                    this.uploadFrame.Huploadify(this._userOptions);
                } else {
                    this.uploadFrame.uploadify('init', this._userOptions);
                }
            },
            _setOptions: function (options) {
                var that = this;
                $.each(options, function (key, value) {
                    that._setOption(key, value);
                });
                $("#" + that.queueID).empty();
                if (isHtml5) {
                    this.uploadFrame.Huploadify('destroy');
                    this.uploadFrame.Huploadify(this._userOptions);
                } else {
                    this.uploadFrame.uploadify('destroy');
                    this.uploadFrame.uploadify('init', this._userOptions);
                }
            },
            _destroy: function () {
                if (isHtml5) {
                    this.uploadFrame.Huploadify('destroy');
                } else {
                    this.uploadFrame.uploadify('destroy');
                }
                this.wrapper.remove();
                this.element.show();
            }
        });
    })(jQuery);
    (function ($) {
        $.widget("custom.cropImageUpload", {
            version: "1.1.1",
            options: {
                imageCropUrl: WE.contextPath + "/app/api/file/crop",
                title: "图片截取",
                selectText: "选择文件",
                cls: "",
                cropable: true,
                buttonWidth: 80,
                aspectRatio: 1,
                onCropComplete: $.noop,
                imgRange: [
                    {
                        id: "normal",
                        width: 36,
                        height: 36
                    },
                    {
                        id: "tiny",
                        width: 16,
                        height: 16
                    }
                ]
            },
            _create: function () {
                this.cache = {};
                this._createCropPanel();
                this._initUploader();
            },
            _createCropPanel: function () {
                if (!this.options.cropable) {
                    return;
                }
                var that = this;
                this.cropId = $.utils.createUUID(6);
                this.cropDg = $("<div style='display:none'></div>").addClass("uploadify-crop-dg").appendTo("body");
                var cropHtml = '<table><tr>\
                               <td class="uploadify-crop-temp">\
                                   <div style="overflow: hidden;width: 400px;margin-right: 15px" id="' + this.cropId + '"></div>\
                               </td>\
                               <td class="uploadify-crop-images">\
                                   {{#.}}<div class="uploadify-crop-image">\
                                   <div style="width:{{width}}px;height: {{height}}px;overflow: hidden"><img width="{{width}}" height="{{height}}" id="' + this.cropId + '_{{id}}" /></div>\
                                     <span>{{width}}*{{height}}</span>\
                                   </div>{{/.}}\
                               </td>\
                          </tr></table>';
                require("plugins/jquery.mustache");
                this.cropDg.html(Mustache.render(cropHtml, that.options.imgRange));
            },
            _crop: function (width, height) {
                var that = this;
                this.cropImage.Jcrop({
                    onChange: showPreview,
                    onSelect: showPreview,
                    aspectRatio: that.options.aspectRatio
                }, function () {
                    var api = this;
                    api.setSelect([0, 0, width , height]);
                });
                function showPreview(coords) {
                    if (parseInt(coords.w) > 0) {
                        var ranges = that.options.imgRange;
                        for (var i = 0; i < ranges.length; i++) {
                            var nx = ranges[i].width / coords.w, ny = ranges[i].height / coords.h;
                            $("#" + that.cropId + "_" + ranges[i].id).css({
                                width: Math.round(nx * width) + 'px',
                                height: Math.round(ny * height) + 'px',
                                marginLeft: '-' + Math.round(nx * coords.x) + 'px',
                                marginTop: '-' + Math.round(ny * coords.y) + 'px'
                            });
                        }
                        that.cache.postData = {
                            x: Math.round(coords.x),
                            y: Math.round(coords.y),
                            width: Math.round(coords.w),
                            height: Math.round(coords.h)
                        };
                    }
                }
            },
            _initUploader: function () {
                var that = this;
                that.element.fileupload({
                    uploader: WE.contextPath + "/app/api/file/uploadForCrop",
                    postData: {type: that.options.type},
                    fileTypeDesc: '*.jpg;*.jpeg;*.gif;*.png;',
                    fileTypeExts: '*.jpg;*.jpeg;*.gif;*.png;',
                    multi: false, queueSizeLimit: 1,
                    selectText: this.options.selectText,
                    cls: this.options.cls,
                    maxUploadNumber: 1,
                    width: this.options.buttonWidth,
                    onUploadSuccess: function (files, first) {
                        if (first) {
                            return;
                        }
                        var $this = this;
                        var myfile = files[0];
                        var attr = {width: myfile.width, height: myfile.height};
                        if (!that.options.cropable || attr.width <= 80) {
                            that._trigger("onCropComplete", null, {el: $this, file: myfile});
                        } else {
                            var url = WE.contextPath + "/print" + myfile.href, width = attr.width, height = attr.height, size;
                            $("#" + that.cropId + "_normal")
                                .add("#" + that.cropId + "_tiny").attr("src", url);
                            that.cropImage = $("#" + that.cropId).html('<img src="' + url + '" alt=""/>').children();

                            require("jcrop/jquery.Jcrop.min.css");
                            require("jcrop/jquery.Jcrop");
                            var ranges = that.options.imgRange;
                            var maxW = 0;
                            for (var i = 0; i < ranges.length; i++) {
                                if (maxW < ranges[i].width) {
                                    maxW = ranges[i].width;
                                }
                            }
                            that.cropDg.show().dialog({
                                closed: true,
                                height: "auto",
                                width: 450 + maxW,
                                modal: true,
                                title: that.options.title,
                                buttons: [
                                    {
                                        text: "确认截取",
                                        handler: function () {
                                            var $d = this;
                                            that.cache.postData = $.extend({}, that.cache.postData, {type: that.options.type, path: myfile.href, size: size});
                                            $.post(that.options.imageCropUrl, that.cache.postData, function (data) {
                                                that.cropDg.dialog("close");
                                                that._trigger("onCropComplete", null, {el: $this, file: data.attachment});
                                            }, "JSON");
                                        }
                                    }
                                ]
                            });
                            that._crop(width, height);
                            that.cropDg.dialog("open");
                            that.cropDg.dialog("move", {top: 30});
                        }
                    }
                });
            }
        });
    })(jQuery);
    var frame = $.utils.createUUID(8);

    function createFrame() {
        var f = $("#" + frame);
        if (!f.length) {
            f = $('<iframe style="display:none" id="' + frame + '"></iframe>').appendTo("body");
        }
        return f;
    }

    exports.download = function (url) {
        var ifram = createFrame();
        ifram.attr("src", url);
    }
});